package com.financing.platform.web;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.financing.platform.dto.CountInfoDTO;
import com.financing.platform.service.ICountInfoService;
import com.financing.platform.util.Dict;
import com.financing.platform.util.StringUtil;

/**
 * 
 * @ClassName: CountInfoAction
 * @Description: 统计信息Action 
 * @author  qiye
 * @date 2014年10月31日 上午9:52:17
 *
 */
@Controller
public class CountInfoAction extends BaseAction{
	
	@Autowired
	private ICountInfoService countInfoServiceImpl;
	
	/**
	 * 
	 * @Title: queryCountInfo
	 * @Description: 运营信息统计 
	 * @param @param request
	 * @param @param response
	 * @param @param countInfoDTO
	 * @param @return   
	 * @return ModelAndView   
	 * @throws
	 */
	@RequestMapping("/queryCountInfo.shtml")
	public ModelAndView queryCountInfo(HttpServletRequest request,
			HttpServletResponse response,String countDateBeginStr, String countDateEndStr) {
		
		this.log.info("begin query count info!");
		
		request.getSession().setAttribute(Dict.requestID, "queryCountInfo.shtml");
		
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		
		Map<String,Object> params = new HashMap<String,Object>();
		
		Map<String,Object> resultMode = new HashMap<String,Object>();
		
		Date countDateBegin = null;
		
		Date countDateEnd = null;
		
		try{
			if(countDateBeginStr == null){
				countDateBegin = StringUtil.rollDay(new Date(), -1);
				countDateBegin = df.parse(df.format(countDateBegin));
			}else{
				countDateBegin = df.parse(countDateBeginStr);
			}
			
			if(countDateEndStr == null){
				countDateEnd = countDateBegin;
			}else{
				countDateEnd = df.parse(countDateEndStr);
			}
			
			params.put("countDateBegin",countDateBegin );
			params.put("countDateEnd", countDateEnd);
			
			List<CountInfoDTO> countInfoList = countInfoServiceImpl.queryCountInfoList(params);
			
			resultMode.putAll(countInfoServiceImpl.queryTotalCountInfo());
			
			resultMode.put("countInfoList", countInfoList);
			resultMode.put("countDateBegin",countDateBegin);
			resultMode.put("countDateEnd", countDateEnd);
			this.log.info("end query count info access !");
		}catch(Exception e){
			log.error("date format error!",e);
		}
		
		return new ModelAndView("countInfoManager", resultMode);
	}
	
}
